/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: LazyInnerClassSingleton.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/2/28 下午12:07
 * LastModified: 2020/02/28 12:07:28
 */

package com.qolome.knowledge.design.pattern.singleton.lazy;

/**
 * @author Qolome
 * @version V1.0
 * @Description 懒汉内部类单例
 * 利用内部类的特性,在调用时才创建
 * 优点: 写法优雅,利用Java本身用法特性,不能被反射破坏
 * 缺点: 代码不够优雅
 * @date 2020年 02月28日 12:07:30
 */
public class LazyInnerClassSingleton {

    private LazyInnerClassSingleton(){
        if(LazyHolder.INSTANCE != null){
            throw new RuntimeException("禁止非法访问");
        }

    }

    private static LazyInnerClassSingleton getInstance(){
        return LazyHolder.INSTANCE;
    }

    private static class LazyHolder{
        private  static final LazyInnerClassSingleton INSTANCE = new LazyInnerClassSingleton();

    }

}
